#! /bin/bash
source ../variable.sh 

rm -f *.tar
version_functions=(set_version_120 set_version_125 set_version_129)
# pull docker images.
# 遍历所有版本设置函数
for version_func in "${version_functions[@]}"; do
    echo "Setting versions using $version_func"
    $version_func  # 调用版本设置函数，设置环境变量

    # 遍历images数组，拉取并保存镜像
    for image_name in "${!images[@]}"; do
        image_version="${images[$image_name]}"
        image_version="${!image_version}"
        
        # 检查版本是否为空
        if [ -z "$version" ]; then
            echo "Version for $image_name is empty, skipping..."
            continue
        fi

        full_image_name="${IMAGE_REPO}/base-aarch64/${image_name}:${version}"
        
        # 执行docker pull & docker save 命令
        echo "Pulling image $full_image_name"
        docker pull "$full_image_name"

        echo "Saving docker image $full_image_name to tar"
        docker save "$full_image_name" -o "${image_name}-${version}.tar"
    done

    echo "All images for $version_func have been pulled and saved."
done

echo "All versions of all images have been pulled and saved."

